package org.niux.AutoLoginQQ.ui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

public class ModifyInfo extends Dialog {

	protected Object result;
	protected Shell shell;
	private Text nickText;
	private Text singleLongNickText;
	private String nick;
	private String singleLongNick;

	/**
	 * Create the dialog.
	 * @param parent
	 * @param style
	 */
	public ModifyInfo(Shell parent, int style) {
		super(parent, style);
		setText("修改昵称和个性签名");
	}

	/**
	 * Open the dialog.
	 * @return the result
	 */
	public Object open() {
		createContents();
		
		// 窗口居中
		int width = shell.getMonitor().getClientArea().width;
		int height = shell.getMonitor().getClientArea().height;

		int x = shell.getSize().x;
		int y = shell.getSize().y;

		if (x > width) {
			shell.getSize().x = width;
		}

		if (y > height) {
			shell.getSize().y = height;
		}

		shell.setLocation((width - x) / 2, (height - y) / 2);
		
		shell.open();
		shell.layout();
		Display display = getParent().getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		return result;
	}

	/**
	 * Create contents of the dialog.
	 */
	private void createContents() {
		
		shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.SYSTEM_MODAL);
		shell.setBackground(SWTResourceManager.getColor(173, 216, 230));
		shell.setSize(292, 300);
		shell.setText(getText());
		
		Label label = new Label(shell, SWT.NONE);
		label.setBackground(SWTResourceManager.getColor(173, 216, 230));
		label.setBounds(10, 10, 61, 25);
		label.setText("昵称：");
		
		nickText = new Text(shell, SWT.BORDER);
		nickText.setBounds(77, 7, 199, 25);
		
		Label label_1 = new Label(shell, SWT.NONE);
		label_1.setBackground(SWTResourceManager.getColor(173, 216, 230));
		label_1.setBounds(10, 41, 61, 25);
		label_1.setText("个性签名：");
		
		singleLongNickText = new Text(shell, SWT.BORDER | SWT.MULTI);
		singleLongNickText.setBounds(77, 41, 199, 154);
		
		Button okBtn = new Button(shell, SWT.NONE);
		okBtn.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				nick = nickText.getText();
				singleLongNick = singleLongNickText.getText();
				shell.close();
			}
		});
		
		okBtn.setBounds(37, 212, 80, 27);
		okBtn.setText("确定");
		
		shell.setDefaultButton(okBtn);
		
		Button cancleBtn = new Button(shell, SWT.NONE);
		cancleBtn.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				shell.close();
			}
		});
		cancleBtn.setBounds(167, 212, 80, 27);
		cancleBtn.setText("取消");

	}

	public String getNick() {
		return nick;
	}

	public void setNick(String nick) {
		this.nick = nick;
	}

	public String getSingleLongNick() {
		return singleLongNick;
	}

	public void setSingleLongNick(String singleLongNick) {
		this.singleLongNick = singleLongNick;
	}
}
